package com.hashcoding.eyes.data.entity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * PhotosList
 *
 * @author Maochuan
 * @date 2016-02-08
 */
public class PhotosList {
    private List<Photo> mList;
    private static PhotosList inst;

    public static PhotosList instance() {
        if (inst == null) {
            inst = new PhotosList();
        }
        return inst;
    }

    public List<Photo> getList() {
        return mList;
    }

    public List<Photo> loadData() {
        return mList.size() != 0
                ? loadData(mList.get(0).id + 1)
                : new ArrayList<Photo>();
    }

    public List<Photo> loadData(int position) {
        List<Photo> photos = new ArrayList<Photo>();

        Iterator<Photo> i = mList.iterator();
        while (i.hasNext()) {
            Photo p = i.next();
            if (p.id <= position)
                break;
        }

        int c = 0;
        while (i.hasNext()) {
            photos.add(i.next());
            if (++c == 10) break;
        }
        return photos;
    }

    private PhotosList() {
        initData();
    }

    private void initData() {
        mList = new ArrayList<Photo>();

        for (int i = 0; i < 25; ++i) {
            mList.add(0, new Photo("mao", "http://littendomo.sinaapp.com/ins/-qKfKxo7nw.jpg", "mao的测试" + i, "mao的description", i % 4 == 0));
        }
    }

    public void insert(String userID, String url, String title, String desc) {
        mList.add(1, new Photo(userID, url, title, desc, false));
    }
}
